#pragma once

#include <math.h>
#include <GL/glut.h>

class Point2   //single point w/ floating point coordinates
{
  public:
	float x, y;
	Point2() {x = y = 0.0f;} //constructor 1
	Point2(float xx, float yy) {x=xx; y=yy;} //constructor 2
	void set(float xx, float yy) {x=xx; y=yy;}
	float getX() {return x;}
	float getY() {return y;}
};

class Basic2DCanvas
{
	Point2 CP;
	float CD;  //current turtle direction
	//array of current turtle locations
	//better to use a linked list for these :)
	//These arrays will allow a maximum of 100 nested [] pairs.   Should be heaps!!
	Point2 saveTut[100];
	float saveAng[100];
	int curr;

public:
	float thickness;
	Basic2DCanvas(void);
	~Basic2DCanvas(void);
	const Point2 & getCP() const {return CP;}
	void setCP(float x, float y) {CP.set(x,y);}
	float getCD() const {return CD;}
	//-----TURTLE DRAWING FUNCTIONS- TAKEN OUT OF CANVAS.H------------------
	void moveTo(float x, float y)
	{
		CP.set(x, y);
	}

	void lineTo(float x, float y)
	{
		glBegin(GL_LINES);
			glVertex2f((GLfloat) CP.getX(), (GLfloat) CP.getY());
			glVertex2f((GLfloat) x, (GLfloat) y); //draw the line
		glEnd();
		CP.set (x, y); //update current point to new point
		//glFlush();
	}

	void turnTo(float ang) {CD=ang;}
	void turn(float ang) {CD+=ang;}
	void forward(float dist, int isVisible)
	{
		glLineWidth(thickness);
		const float rpd=0.017453393;
		float x1 = CP.x + dist*cos(rpd*CD);
		float y1 = CP.y + dist*sin(rpd*CD);
		if(isVisible)
			lineTo(x1,y1);
		else
			moveTo(x1,y1);
	}

	void saveTurtle()
	{
		saveTut[curr].set(CP.x, CP.y);
		saveAng[curr] = CD;
		curr++;
	}

	void restoreTurtle()
	{
		curr--;
		moveTo(saveTut[curr].getX(),saveTut[curr].getY());
		turnTo(saveAng[curr]);
	}
};

